cmake_minimum_required(VERSION 3.8)
set(PROJECT_NAME KGL)
project(${PROJECT_NAME})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED FALSE)

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif ()

# GLFW
set(GLFW_DIR 3rd_party/GLFW)
option(GLFW_BUILD_EXAMPLES OFF)
option(GLFW_BUILD_TESTS OFF)
option(GLFW_BUILD_DOCS OFF)
add_subdirectory(${GLFW_DIR})
include_directories(${GLFW_DIR}/include)
LIST(APPEND LIBS glfw ${GLFW_LIBRARIES})

# glad
set(GLAD_DIR 3rd_party/glad)
set(GLAD_SRC ${GLAD_DIR}/src/glad.c)
include_directories(${GLAD_DIR}/include)

# glm
set(GLM_DIR 3rd_party/glm)
include_directories(${GLM_DIR})

# spdlog
option(SPDLOG_BUILD_EXAMPLES OFF)
option(SPDLOG_BUILD_TESTING OFF)
set(SPDLOG_DIR 3rd_party/spdlog)
add_subdirectory(${SPDLOG_DIR})
include_directories(${SPDLOG_DIR}/include)

# stb
#add_definitions(-DSTB_IMAGE_IMPLEMENTATION -DSTB_IMAGE_WRITE_IMPLEMENTATION)
add_subdirectory(3rd_party/stb)
list(APPEND LIBS STB)
include_directories(3rd_party/stb)

# KPBR
add_subdirectory(3rd_party/KPBR)
list(APPEND LIBS KPBR)
include_directories(3rd_party/KPBR/src)

# imgui
add_subdirectory(3rd_party/imgui)
list(APPEND LIBS imgui)
include_directories(3rd_party/imgui)

# assimp
option(ASSIMP_BUILD_ASSIMP_TOOLS OFF)
option(ASSIMP_BUILD_SAMPLES OFF)
option(ASSIMP_BUILD_TESTS OFF)
add_subdirectory(3rd_party/assimp)
list(APPEND LIBS assimp)
include_directories(3rd_party/assimp/include)

if (MSVC)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
else ()
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -std=c++17")
    if (NOT WIN32)
        LIST(APPEND LIBS dl)
    endif ()
endif ()

# project
file(GLOB_RECURSE SOURCE_FILES src/*.cpp)
list(APPEND SOURCE_FILES ${GLAD_SRC})
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
include_directories(src)
target_link_libraries(${PROJECT_NAME} ${LIBS})